package com.pan.kang.flow;

import com.pan.kang.dto.CreateOrderDto;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.slot.Slot;

import java.util.List;
import java.util.stream.Collectors;

@LiteflowComponent(id = "normal", name = "现货订单创建")
public class NormalOrderCreate extends NodeComponent {

    @Override
    public <T> void beforeProcess(String nodeId, Slot slot) {
        // 现货创建订单前业务逻辑检查
        CreateOrderDto createOrderDto = this.getContextBean(CreateOrderDto.class);
        List<CreateOrderDto.Goods> goodsList = createOrderDto.getGoodsList();
        List<String> skuIds = goodsList.stream().map(CreateOrderDto.Goods::getSkuId)
                .distinct().collect(Collectors.toList());
        // 调用商品领域API，参数sku集合，校验库存及是否上架，限购等业务逻辑
        super.beforeProcess(nodeId, slot);
    }


    @Override
    public void process() throws Exception {
        System.out.println("现货订单创建");
    }

    @Override
    public void onError() throws Exception {
        // 创建订单失败回调
    }
}
